package com.example.demo.service;

import com.example.demo.entity.Userinfo;
import com.example.demo.mapper.UserMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * Description: 用户服务层
 */
@Service
public class UserService {
    @Autowired
    private UserMapper mapper;

    // 新增用户信息
    public Integer insertUser(Userinfo userinfo) {
        try {
            return mapper.insertUser(userinfo);
        } catch (Exception e) {
            return -1;
        }
    }

    // 根据用户名获取用户信息
    public Userinfo getUserByName(String username) {
        return mapper.getUserByName(username);
    }

    // 根据用户 id 查询用户信息
    public Userinfo getUserById(Integer id) {
        return mapper.getUserById(id);
    }
}
